package com.jrapider;

import com.jrapider.session.SessionFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.context.request.RequestContextListener;

/**
 * @Auther: hxs
 * @Date: 2019/1/4
 * @Description:
 */
@Configuration
public class WebRegister {
    @Bean
    public FilterRegistrationBean sessionFilterRegistration(SessionFilter sessionFilter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(sessionFilter);
        registration.addUrlPatterns("/*"); //
        registration.setName(SessionFilter.class.getSimpleName());
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
    @Bean
    public ServletListenerRegistrationBean listenerRegistrationBean(){
        ServletListenerRegistrationBean registrationBean = new ServletListenerRegistrationBean();
        registrationBean.setListener(new RequestContextListener());
        return registrationBean;
    }

}
